package utils

import (
	"crypto/md5"
	"encoding/hex"
	"io"
	"os"
)

func FileMD5(filePath string) (string, error) {
	file, err := os.Open(filePath)
	if err != nil {
		return "", err
	}
	hash := md5.New()
	_, _ = io.Copy(hash, file)
	md5Bytes := hash.Sum(nil)                 // 获取 MD5 字节数组
	md5String := hex.EncodeToString(md5Bytes) // 转换为十六进制字符串表示
	return md5String, nil
}
